<?php
class Setting_model extends Mymodel {
	public $table_name 	= "system_settings";
    function Setting_model()
    {
        parent::Mymodel();
    }
	
	
	
	function saveSetting($type,$data)
	{

		$this->db->delete($this->table_name, array('username' => $this->session->userdata('username'),'type'=>$type));
		
		$savedata['username']=$this->session->userdata('username');
		$savedata['type']=$type;
		$savedata['value']=serialize($data);
		return $this->insert_new_record($this->table_name , $savedata);

	}

	function getSetting($type){
		$reportSetting=$this->get_data($this->table_name,NULL,array('username' => $this->session->userdata('username'),'type'=>$type));
		if(!empty($reportSetting[0]))$setting=unserialize($reportSetting[0]['Value']);
		if(empty($setting)){
			$reportSetting=$this->get_data($this->table_name,NULL,array('username'=>'root','type'=>$type));
			if(!empty($reportSetting[0])) $setting=unserialize($reportSetting[0]['Value']);
		}
		
		if(!empty($setting))	return	$setting;
		return array();
	}	
}
